#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
交易 - 支付宝WAP支付功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))

from examples.base_example import BaseExample
from jlpay.services.trans.mini.alipay.wap_pay_service import WapPayService
from jlpay.model.trans.mini.alipay.wap_pay import (
    WapPayRequest, WapPayResponse
)


class WapPayExample(BaseExample):
    """支付宝WAP支付示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.trans.mini.alipay.wap_pay")
        self.service = WapPayService(self.config)
    
    def build_wap_pay_request(self):
        """
        构建支付宝WAP支付请求
        
        Returns:
            WapPayRequest实例
        """
        request = WapPayRequest()
        request.set_mch_id("849584358120018")
        request.set_term_no("60131234")
        request.set_pay_type("alipay")
        request.set_buyer_logon_id("test@alipay.com")
        request.set_buyer_id("2088102122458832")
        request.set_limit_pay("no_credit")
        request.set_out_trade_no("TEST_WAP_PAY_001")
        request.set_payment_valid_time("20241231235959")
        request.set_body("测试支付宝WAP支付商品")
        request.set_attach("测试支付宝WAP支付描述")
        request.set_total_fee("200")
        request.set_is_hire_purchase("0")
        request.set_hire_purchase_num("3")
        request.set_hire_purchase_seller_percent("0")
        request.set_remark("测试支付宝WAP支付备注")
        request.set_notify_url("https://example.com/notify")
        request.set_op_user_id("test_user")
        request.set_op_shop_id("GD_SZ_001")
        request.set_device_info("N50007A8890")
        request.set_mch_create_ip("127.0.0.1")
        request.set_longitude("116.397128")
        request.set_latitude("39.916527")
        return request
    
    def demo(self):
        """执行支付宝WAP支付示例"""
        self.logger.info("开始执行支付宝WAP支付示例")
        
        # 构建请求
        request = self.build_wap_pay_request()
        
        # 发送请求并处理响应
        self.send_request_and_handle_response(
            self.service.wap_pay,
            "支付宝WAP支付",
            request
        )
        
        self.logger.info("支付宝WAP支付示例执行完毕")


if __name__ == "__main__":
    logger = WapPayExample().logger
    logger.info("==================================================")
    logger.info("===== 支付宝WAP支付示例 开始 =====")
    logger.info("==================================================")
    
    example = WapPayExample()
    example.demo()
    
    logger.info("==================================================")
    logger.info("===== 支付宝WAP支付示例执行完毕 =====")
    logger.info("==================================================") 